<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String contextPath = request.getContextPath();
	request.setAttribute("contextPath", contextPath);
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<title>词汇管理</title>

<script src="${contextPath}/js/jquery.min.js"></script>

<!-- Bootstrap Core CSS -->
<link href="${contextPath}/css/bootstrap.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="${contextPath}/css/metisMenu.min.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="${contextPath}/css/sb-admin-2.min.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="${contextPath}/css/font-awesome.min.css" rel="stylesheet"
	type="text/css">

<!--common Css-->
<link href="${contextPath}/css/common.css" rel="stylesheet">
<link href="${contextPath}/iconfont/iconfont.css" rel="stylesheet">

<!--information Css-->
<link href="${contextPath}/css/information.css" rel="stylesheet">

<!-- jQuery -->
<link rel="stylesheet"
	href="${contextPath}/css/umeditor/themes/default/css/umeditor.min.css">
<script src="${contextPath}/js/jquery.min.js"></script>
<script src="${contextPath}/css/umeditor/third-party/template.min.js"></script>
<script src="${contextPath}/css/umeditor/umeditor.config.js"></script>
<script src="${contextPath}/css/umeditor/umeditor.js"></script>
<script src="${contextPath}/css/umeditor/lang/zh-cn/zh-cn.js"></script>
</head>

<body>

	<div id="wrapper">

		<%@include file="nav.jsp"%>

		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h3 class="page-header">词汇管理</h3>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<button class="btn btn-primary" type="button" id="addNotice">新增词汇</button>
						</div>
						<!-- /.panel-heading -->
						<div class="panel-body">
							<table width="100%" class="table table-striped table-hover"
								id="dataTables-example">
								<thead>
									<tr>
										<th>ID</th>
										<th>内容</th>
										<th>发布时间</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${bannedWords.list}" var="item" varStatus="status">

										<tr class="odd gradeX">
											<td>${ bannedWords.data.startPage  +  status.index + 1}</td>
											<td>${item.wordsInfo}</td>
											<td><fmt:formatDate type="date" value="${item.wordsDate}" /></td>
											<td><a href="javascript:void(0)" class="edit" onclick="editNotice(${item.id})"><i class="iconfont icon-75bianji"></i></a> 
											   <a href="javascript:void(0)" class="delete" onclick="deleteNotice(${item.id})"><i class="iconfont icon-shanchu"></i></a>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
							<nav aria-label="Page navigation" class="pull-right">
							<ul class="pagination">

								<c:if test="${ bannedWords.data.pageNow != 1 }">
									<li><a
										href="${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow=${ bannedWords.data.pageNow - 1 }"
										aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
									</a></li>
								</c:if>
								<c:if test="${ bannedWords.data.pageNow == 1 }">
									<li><a href="#" aria-label="Previous"> <span
											aria-hidden="true">&laquo;</span>
									</a></li>
								</c:if>

								
								<li><input type="text"  disabled="disabled" id="turn" value="${ bannedWords.data.pageNow }/${ bannedWords.data.totalPageCount }"></li>


								<c:if
									test="${ bannedWords.data.pageNow != bannedWords.data.totalPageCount }">
									<li><a
										href="${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow=${ bannedWords.data.pageNow + 1 }"
										aria-label="Next"> <span aria-hidden="true">&raquo;</span>
									</a></li>
								</c:if>
								<c:if
									test="${ bannedWords.data.pageNow == bannedWords.data.totalPageCount }">
									<li><a href="#" aria-label="Next"> <span
											aria-hidden="true">&raquo;</span>
									</a></li>
								</c:if>
								<li><input type="text" id="turnGo"></li>
								<li><a href="javascript:turn();">跳转</a></li>
							</ul>
							</nav>
						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
			</div>
		</div>
		<!-- /#page-wrapper -->

	</div>
	<!-- /#wrapper -->

	<!-- 修改词汇 -->
	<div class="modal fade" id="noticeModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改词汇</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" role="form" method="" action="">
						<div class="form-group">
							<label for="content" class="col-sm-2 control-label">编辑内容</label>

							<input type="hidden" name="stuno5" id="noticeid" />

							<div class="col-sm-8">
								<textarea class="form-control" id="noticeinfo" name="noticeinfo"></textarea>
							</div>
						</div>
					</form>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id="save"  onclick="save()">确定</button>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 新增词汇 -->
	<div class="modal fade" id="addnotice" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">新增词汇</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" role="form" method="" action="">
						<div class="form-group">
							<label for="content" class="col-sm-2 control-label">编辑内容</label>
							<div class="col-sm-8">
								<textarea class="form-control" id="addinfo" name="addinfo"></textarea>
							</div>
						</div>
					</form>

				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id="save"  onclick="add()">确定</button>
				</div>
			</div>
		</div>
	</div>

	<!-- 点击删除 -->
	<div class="modal fade" tabindex="-1" role="dialog" id="modal">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					
					<input type="hidden" name="stuno5" id="deleteid" />
					
					<h4 class="modal-title">提示信息</h4>
				</div>
				<div id="notice"></div>
				<div class="modal-body">
					<p>确定删除吗?</p>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" id="sure"  onclick="deleteId()">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->

	<!-- 提示数据异常 -->
	<div class="modal fade" tabindex="-1" role="dialog" id="errormodal">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">提示信息</h4>
				</div>
				<div id="notice"></div>
				<div class="modal-body">
					<p>数据异常,请刷新重试!</p>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->



	<!-- Bootstrap Core JavaScript -->
	<script src="${contextPath}/js/bootstrap.min.js"></script>

	<!-- Metis Menu Plugin JavaScript -->
	<script src="${contextPath}/js/metisMenu.min.js"></script>

	<!-- Custom Theme JavaScript -->
	<script src="${contextPath}/js/sb-admin-2.min.js"></script>

	<!-- Page-Level Demo Scripts - Tables - Use for reference -->
	<script>
    $(function () {
        $('[data-toggle="popover"]').popover();

        $("#addNotice").click(function(){
            $("#myModalLabel").html('新增词汇');
            $("#addnotice").modal('show');
        });

        window.um = UM.getEditor('content', {
            toolbar: ['undo redo | bold italic underline'],
            initialFrameWidth: '360',
            initialFrameHeight: '200'
        });

        //点击修改
        $(".edit").on('click', function(){
            $("#myModalLabel").html('编辑词汇');
            $("#noticeModal").modal('show');
        });

        //点击删除
        $(".delete").on('click', function(){
            $("#modal").modal('show');
        });

        /* 获取编辑器内容 */
        //var html = um.getContent();
        //var txt = um.getContentTxt();

        /* 设置编辑器内容 */
        //um.setContent('要设置的编辑器内容.');

        //点击提交
        $("#save").click(function(){
            var val = um.getContent();
            if(val === ''){
                notice('请输入');
                return false;
            }
        });

        //提示信息封装函数
        function notice(notice) {
            var str = '';
            str += '<div class="popupTip">';
            str += notice;
            str += '<span class="glyphicon glyphicon-remove"></span>';
            str += '</div>';
            str += '</strong></div>';
            //wrapper插入str
            $("#wrapper").append(str);
        }

        //取消提示框
        $("#wrapper").on('click', '.glyphicon-remove', function(){
            $(".popupTip") .hide();
        });
    });
    
    function dispear(){
        setTimeout(function(){
        }, 3000);
        $(".popupTip").hide();
    }
    
    /*  点击修改 */
    function editNotice(a) {
		//获取数据
	 	$.ajax({
	 	    type: "POST",
	 	    url: "${contextPath}/WebManager/bannedwords/oneBannedWords?id="+a,
	 	    dataType:'json', 
	 	    contentType: "application/json;charset=utf-8",
	 	    data:{i:1},
	 	    success: function(data){
	 	    	if(data.status != 1){
	 	    		$('#noticeinfo').val(data.data.wordsInfo);
	 	    		$('#noticeid').val(data.data.id);
	 	    	    $("#myModalLabel").html('修改词汇');
	 	            $("#noticeModal").modal('show');
				}else{
					 $("#errormodal").modal('show');
				}
	 	    }
	 	}); 
	} 
    
    
    /* 点击修改中的确定 */
    function save() {
		//获取数据
		var noticeInfo =  $('#noticeinfo').val();
		var noticeId =  $('#noticeid').val();
		$.post("${contextPath}/WebManager/bannedwords/editBannedWords",{id:noticeId,bannedWordsInfo:noticeInfo},function(data){
	  		if(data.status != 1){
	  			window.location.href = "${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow=1";
			}else{
				 $("#errormodal").modal('show');
			}
		});
	} 

    /* 点击删除 */
    function deleteNotice(a) {
    	 $('#deleteid').val(a)
    	 $("#modal").modal('show');
	} 
    
    
    /* 点击删除确认 */
    function deleteId() {
    	var a  =  $('#deleteid').val();
		$.post("${contextPath}/WebManager/bannedwords/deletetBannedWords",{id:a},function(data){
	  		if(data.status != 1){
	  			window.location.href = "${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow=1";
			}else{
				 $("#errormodal").modal('show');
			}
		});
	} 
    
    /* 点击添加确认 */
    function add() {
    	var info  =  $('#addinfo').val();
		$.post("${contextPath}/WebManager/bannedwords/setBannedWords",{bannedWordsInfo:info},function(data){
	  		if(data.status != 1){
	  			window.location.href = "${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow=1";
			}else{
				 $("#errormodal").modal('show');
			}
		});
	} 
    
    function turn(){
    	var text = $('#turnGo').val();
    	var reg = /^\+?[1-9][0-9]*$/;
        if (!reg.test(text)) {
        	alert('请输入正整数');
            dispear();
            return;
        } 
        if(text-${ bannedWords.data.totalPageCount }>0){
        	alert('请输入合理页数');
            dispear();
            return;
        }
    	console.log(text);
    	window.location.href = "${contextPath}/WebManager/bannedwords/bannedWordsPage?pageNow="+text; 	
    }
    </script>

</body>

</html>
